﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Schedule.Data;

namespace Schedule.DataService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ScheduleService" in code, svc and config file together.
    [ServiceContract]
    public class ScheduleService
    {
        //ExampleSilverlightEntities data= new ExampleSilverlightEntities();
        ScheduleEntities db = new ScheduleEntities();
        //#region Event_Competitor
        //[OperationContract]
        //public IEnumerable<Event> getAllEvent()
        //{
        //    //using (var data = new ExampleSilverlightEntities())
        //    //{
        //    //    var res = data.Events.ToList();
        //    //    res.ForEach(e => data.Detach(e));
        //    //    return res;

        //    //}
        //    var res= data.Events.ToList();
        //    res.ForEach(e => data.Detach(e));
        //    return res;

        //}

        //[OperationContract]
        //public IEnumerable<Competitor> getAllCompetitor(int EventID)
        //{
        //    //using (var data = new ExampleSilverlightEntities())
        //    //{
        //    //    var res = (from p in data.Competitors where p.EventID == EventID select p).ToList();
        //    //    res.ForEach(e => data.Detach(e));
        //    //    return res;

        //    //}
        //    var res = (from p in data.Competitors where p.EventID == EventID select p).ToList();
        //    res.ForEach(e => data.Detach(e));
        //    return res;
        //}

        //[OperationContract]
        //public void saveCompetitor(Competitor competitor)
        //{
        //    //using (var data = new ExampleSilverlightEntities())
        //    //{
        //    //    //data.Attach(competitor);
        //    //    //data.ObjectStateManager.ChangeObjectState(competitor, System.Data.EntityState.Modified);
        //    //    //var res = (from p in data.Competitor where p.CompetitorID == competitor.CompetitorID select p).First();
        //    //    //res.TotalTime = competitor.TotalTime;
        //    //    var res = (from p in data.Competitors where p.CompetitorID == competitor.CompetitorID select p).First();
        //    //    //res.TotalTime = competitor.TotalTime;
        //    //    res.Nation = competitor.Nation;
        //    //    res.LastName = competitor.LastName;
        //    //    res.TotalTime = competitor.TotalTime;
        //    //    data.SaveChanges();

        //    //}
        //    var res = (from p in data.Competitors where p.CompetitorID == competitor.CompetitorID select p).First();
        //        //res.TotalTime = competitor.TotalTime;
        //        res.Nation = competitor.Nation;
        //        res.LastName = competitor.LastName;
        //        res.TotalTime = competitor.TotalTime;
        //        data.SaveChanges();
        //}

        //[OperationContract]
        //public void deleteCompetitor(Competitor competitor)
        //{
        //    //using (var data = new ExampleSilverlightEntities())
        //    //{
        //    //    //data.Attach(competitor);
        //    //    //data.ObjectStateManager.ChangeObjectState(competitor, System.Data.EntityState.Deleted);
        //    //    //data.Competitors.DeleteObject(competitor);
        //    //    var res = from p in data.Competitors where p.CompetitorID == competitor.CompetitorID select p;
        //    //    data.Competitors.DeleteObject(res.First());
        //    //    data.SaveChanges();

        //    //}
        //    var res = from p in data.Competitors where p.CompetitorID == competitor.CompetitorID select p;
        //        data.Competitors.DeleteObject(res.First());
        //        data.SaveChanges();
        //}

        //[OperationContract]
        //public void insertCompetitor(Competitor competitor)
        //{
        //    //using (var data = new ExampleSilverlightEntities())
        //    //{
        //    //    //data.Attach(competitor);
        //    //    //data.ObjectStateManager.ChangeObjectState(competitor, System.Data.EntityState.Added);
        //    //    data.Competitors.AddObject(competitor);
        //    //    //var res = (from p in data.Competitor where p.CompetitorID == competitor.CompetitorID select p).First();
        //    //    //res.TotalTime = competitor.TotalTime;
        //    //    data.SaveChanges();

        //    //}
        //    //competitor.Event = null;
        //    data.Competitors.AddObject(competitor);
        //    data.SaveChanges();
        //}
        //#endregion

        [OperationContract]
        public IEnumerable<LOAICB> getAllLoaiCB()
        {
            var res = db.LOAICBs.ToList();
            //res.ForEach(e => db.Detach(e));
            return res;

        }
        [OperationContract]
        public IEnumerable<GIOITINH> getAllGioiTinh()
        {
            var res = db.GIOITINHs.ToList();
            //res.ForEach(e => db.Detach(e));
            return res;

        }
        #region Room
        [OperationContract]
        public LOAIPHONG getLoaiPhongByID(int id)
        {
            var res = from p in db.LOAIPHONGs where p.ID == id select p;
            return res.First();

        }

        [OperationContract]
        public IEnumerable<LOAIPHONG> getAllLoaiPhong()
        {
            var res = db.LOAIPHONGs.ToList();
            //res.ForEach(e => db.Detach(e));
            return res;

        }

        [OperationContract]
        public IEnumerable<PHONG> getAllPhong()
        {
            var res = db.PHONGs.ToList();
            //res.ForEach(e => db.Detach(e));
            return res;
        }

        [OperationContract]
        public void savePhong(PHONG phong)
        {
            var res = (from p in db.PHONGs where p.ID == phong.ID select p).First();
            res.LoaiPhongID = phong.LoaiPhongID;
            res.MaPhong = phong.MaPhong;
            res.SucChua = phong.SucChua;
            res.TenPhong = phong.TenPhong;
            res.TrangThai = phong.TrangThai;
            db.SaveChanges();
        }

        [OperationContract]
        public void deletePhong(PHONG phong)
        {
            var res = from p in db.PHONGs where p.ID== phong.ID select p;
            db.PHONGs.DeleteObject(res.First());
            db.SaveChanges();
        }

        [OperationContract]
        public void insertPhong(PHONG phong)
        {
            PHONG res = new PHONG();
            res.LoaiPhongID = phong.LoaiPhongID;
            res.MaPhong = phong.MaPhong;
            res.SucChua = phong.SucChua;
            res.TenPhong = phong.TenPhong;
            res.TrangThai = phong.TrangThai;
            db.PHONGs.AddObject(res);
            db.SaveChanges();
        }
        #endregion

        #region Monhoc
        [OperationContract]
        public IEnumerable<MONHOC> getAllMonhoc()
        {
            var res = db.MONHOCs.ToList();
            return res;

        }

        [OperationContract]
        public void saveMonhoc(MONHOC monhoc)
        {
            var res = (from p in db.MONHOCs where p.ID == monhoc.ID select p).First();
            res.MaMon = monhoc.MaMon;
            res.TenMon = monhoc.TenMon;
            res.SoTinChi = monhoc.SoTinChi;
            db.SaveChanges();
        }

        [OperationContract]
        public void deleteMonhoc(MONHOC Monhoc)
        {
            var res = from p in db.MONHOCs where p.ID == Monhoc.ID select p;
            db.MONHOCs.DeleteObject(res.First());
            db.SaveChanges();
        }

        [OperationContract]
        public void insertMonhoc(MONHOC Monhoc)
        {
            MONHOC res = new MONHOC();
            res.MaMon = Monhoc.MaMon;
            res.TenMon = Monhoc.TenMon;
            res.SoTinChi = Monhoc.SoTinChi;
            db.MONHOCs.AddObject(res);
            db.SaveChanges();
        }
        #endregion

        #region Lophoc
        [OperationContract]
        public IEnumerable<LOPHOC> getAllLophoc()
        {
            var res = db.LOPHOCs.ToList();
            res.ForEach(e => db.Detach(e));
            return res;

        }

        [OperationContract]
        public void saveLophoc(LOPHOC Lophoc)
        {
            //var res = (from p in db.PHONGs where p.ID == phong.ID select p).First();
            db.Attach(Lophoc);
            db.ObjectStateManager.ChangeObjectState(Lophoc, System.Data.EntityState.Modified);
            db.SaveChanges();
        }

        [OperationContract]
        public void deleteLophoc(LOPHOC Lophoc)
        {
            var res = from p in db.LOPHOCs where p.ID == Lophoc.ID select p;
            db.LOPHOCs.DeleteObject(res.First());
            db.SaveChanges();
        }

        [OperationContract]
        public void insertLophoc(LOPHOC Lophoc)
        {
            db.LOPHOCs.AddObject(Lophoc);
            db.SaveChanges();
        }
        #endregion

        #region Teacher
        [OperationContract]
        public IEnumerable<GIANGVIEN> getAllGiangvien()
        {
            var res = db.GIANGVIENs.ToList();
            //res.ForEach(e => db.Detach(e));
            return res;

        }

        [OperationContract]
        public void saveGiangvien(GIANGVIEN Giangvien)
        {
            var res = (from p in db.GIANGVIENs where p.GiangVienID == Giangvien.GiangVienID select p).First();
            res.DiaChi = Giangvien.DiaChi;
            res.GioiTinh = Giangvien.GioiTinh;
            res.HoTen = Giangvien.HoTen;
            res.LoaiCB_ID = Giangvien.LoaiCB_ID;
            res.MaDonVi = Giangvien.MaDonVi;
            res.MaKhoa_ID = Giangvien.MaKhoa_ID;
            res.NgaySinh = Giangvien.NgaySinh;
            res.NghiViec = Giangvien.NghiViec;
            res.SoDT = Giangvien.SoDT;
            res.UserID = Giangvien.UserID;
            db.SaveChanges();
        }

        [OperationContract]
        public void deleteGiangvien(GIANGVIEN Giangvien)
        {
            var res = from p in db.GIANGVIENs where p.GiangVienID == Giangvien.GiangVienID select p;
            db.GIANGVIENs.DeleteObject(res.First());
            db.SaveChanges();
        }

        [OperationContract]
        public void insertGiangvien(GIANGVIEN Giangvien)
        {
            GIANGVIEN res = new GIANGVIEN();
            res.DiaChi = Giangvien.DiaChi;
            res.GioiTinh = Giangvien.GioiTinh;
            res.HoTen = Giangvien.HoTen;
            res.LoaiCB_ID = Giangvien.LoaiCB_ID;
            res.MaDonVi = Giangvien.MaDonVi;
            res.MaKhoa_ID = Giangvien.MaKhoa_ID;
            res.NgaySinh = Giangvien.NgaySinh;
            res.NghiViec = Giangvien.NghiViec;
            res.SoDT = Giangvien.SoDT;
            res.UserID = Giangvien.UserID;
            db.GIANGVIENs.AddObject(res);
            db.SaveChanges();
        }
        #endregion

        #region Teachable_Subject
        [OperationContract]
        public IEnumerable<MONHOCGIANGDAY> getAllMonhocGiangday(int GiangVienID)
        {
            var res = (from p in db.MONHOCGIANGDAYs where p.GiangVienID == GiangVienID select p).ToList();
            //res.ForEach(e => db.Detach(e));
            return res;

        }

        [OperationContract]
        public void saveMonhocGiangday(MONHOCGIANGDAY MonhocGiangday)
        {
            var res = (from p in db.MONHOCGIANGDAYs where p.ID == MonhocGiangday.ID select p).First();
            res.GiangVienID = MonhocGiangday.GiangVienID;
            res.MonHocID = MonhocGiangday.MonHocID;
            db.SaveChanges();
        }

        [OperationContract]
        public void deleteMonhocGiangday(MONHOCGIANGDAY MonhocGiangday)
        {
            var res = from p in db.MONHOCGIANGDAYs where p.ID == MonhocGiangday.ID select p;
            db.MONHOCGIANGDAYs.DeleteObject(res.First());
            db.SaveChanges();
        }

        [OperationContract]
        public void insertMonhocGiangdayn(MONHOCGIANGDAY MonhocGiangday)
        {
            MONHOCGIANGDAY res = new MONHOCGIANGDAY();
            res.GiangVienID = MonhocGiangday.GiangVienID;
            res.MonHocID = MonhocGiangday.MonHocID;
            db.MONHOCGIANGDAYs.AddObject(res);
            db.SaveChanges();
        }
        #endregion

        #region Teachable_Time
        [OperationContract]
        public IEnumerable<THOIGIANGIANGDAY> getAllThoigianGiangday(int GiangVienID)
        {
            var res = (from p in db.THOIGIANGIANGDAYs where p.GiangVienID == GiangVienID select p).ToList();
            return res;

        }
        [OperationContract]
        public IEnumerable<THOIGIAN> getAllThoigian()
        {
            var res = (from p in db.THOIGIANs select p).ToList();
            return res;

        }
        [OperationContract]
        public IEnumerable<THU> getAllThu()
        {
            var res = (from p in db.THUs select p).ToList();
            return res;

        }
        [OperationContract]
        public void saveThoigianGiangday(THOIGIANGIANGDAY ThoigianGiangday)
        {
            var res = (from p in db.THOIGIANGIANGDAYs where p.ID == ThoigianGiangday.ID select p).First();
            res.GiangVienID = ThoigianGiangday.GiangVienID;
            res.ThoiGianID = ThoigianGiangday.ThoiGianID;
            res.ThuID = ThoigianGiangday.ThuID;
            db.SaveChanges();
        }

        [OperationContract]
        public void deleteThoigianGiangday(THOIGIANGIANGDAY ThoigianGiangday)
        {
            var res = from p in db.THOIGIANGIANGDAYs where p.ID == ThoigianGiangday.ID select p;
            db.THOIGIANGIANGDAYs.DeleteObject(res.First());
            db.SaveChanges();
        }

        [OperationContract]
        public void insertThoigianGiangday(THOIGIANGIANGDAY ThoigianGiangday)
        {
            THOIGIANGIANGDAY res = new THOIGIANGIANGDAY();
            res.GiangVienID = ThoigianGiangday.GiangVienID;
            res.ThoiGianID = ThoigianGiangday.ThoiGianID;
            res.ThuID = ThoigianGiangday.ThuID;
            db.THOIGIANGIANGDAYs.AddObject(res);
            db.SaveChanges();
        }
        #endregion

        #region DonVi

        [OperationContract]
        public IEnumerable<DONVI> getAllDonVi()
        {
            var res = db.DONVIs.ToList();
            //res.ForEach(e => db.Detach(e));
            return res;

        }


        [OperationContract]
        public void saveDonVi(DONVI DonVi)
        {
            var res = (from p in db.DONVIs where p.ID == DonVi.ID select p).First();
            res.MaDV = DonVi.MaDV;
            res.KhoaID = DonVi.KhoaID;
            res.DonVi1 = DonVi.DonVi1;
            db.SaveChanges();
        }

        [OperationContract]
        public void deleteDonVi(DONVI DonVi)
        {
            var res = from p in db.DONVIs where p.ID == DonVi.ID select p;
            db.DONVIs.DeleteObject(res.First());
            db.SaveChanges();
        }

        [OperationContract]
        public void insertDonVi(DONVI DonVi)
        {
            DONVI res = new DONVI();
            res.MaDV = DonVi.MaDV;
            res.KhoaID = DonVi.KhoaID;
            res.DonVi1 = DonVi.DonVi1;
            db.DONVIs.AddObject(res);
            db.SaveChanges();
        }
        #endregion

        #region Khoa

        [OperationContract]
        public IEnumerable<KHOA> getAllKhoa()
        {
            var res = db.KHOAs.ToList();
            //res.ForEach(e => db.Detach(e));
            return res;

        }


        [OperationContract]
        public void saveKhoa(KHOA Khoa)
        {
            var res = (from p in db.KHOAs where p.ID == Khoa.ID select p).First();
            res.MaKhoa = Khoa.MaKhoa;
            res.TenKhoa = Khoa.TenKhoa;
            db.SaveChanges();
        }

        [OperationContract]
        public void deleteKhoa(KHOA Khoa)
        {
            var res = from p in db.KHOAs where p.ID == Khoa.ID select p;
            db.KHOAs.DeleteObject(res.First());
            db.SaveChanges();
        }

        [OperationContract]
        public void insertKhoa(KHOA Khoa)
        {
            KHOA res = new KHOA();
            res.MaKhoa = Khoa.MaKhoa;
            res.TenKhoa = Khoa.TenKhoa;
            db.KHOAs.AddObject(res);
            db.SaveChanges();
        }
        #endregion

        #region CTDT
        [OperationContract]
        public IEnumerable<HOCKY> getAllHocky()
        {
            var res = db.HOCKies.ToList();
            //res.ForEach(e => db.Detach(e));
            return res;

        }

        [OperationContract]
        public IEnumerable<CTDT> getAllCTDT()
        {
            var res = db.CTDTs.ToList();
            //res.ForEach(e => db.Detach(e));
            return res;

        }


        [OperationContract]
        public void saveCTDT(CTDT CTDT)
        {
            var res = (from p in db.CTDTs where p.ID == CTDT.ID select p).First();
            res.HocKy_ID = CTDT.HocKy_ID;
            res.Khoa_ID = CTDT.Khoa_ID;
            res.MonHoc_ID = CTDT.MonHoc_ID;
            db.SaveChanges();
        }

        [OperationContract]
        public void deleteCTDT(CTDT CTDT)
        {
            var res = from p in db.CTDTs where p.ID == CTDT.ID select p;
            db.CTDTs.DeleteObject(res.First());
            db.SaveChanges();
        }

        [OperationContract]
        public void insertCTDT(CTDT CTDT)
        {
            CTDT res = new CTDT();
            res.HocKy_ID = CTDT.HocKy_ID;
            res.Khoa_ID = CTDT.Khoa_ID;
            res.MonHoc_ID = CTDT.MonHoc_ID;
            db.CTDTs.AddObject(res);
            db.SaveChanges();
        }
        #endregion

        #region TKB
        private List<List<TKB_TUAN>> Schedule()
        {
            //throw new NotImplementedException();
            List<List<TKB_TUAN>> TKB = CreateTKB();
            var lstTeacher = getAllGiangvien().ToList();
            var lstPhong = getAllPhong().ToList();

            int[,] mangTGDayGV = new int[lstTeacher.Count() + 1, 28];
            int[,] mangTGDayRoom = new int[lstPhong.Count() + 1, 28];

            for (int z = 0; z < TKB.Count; z++)
            {
                int[] mangTGDayClass = new int[28];
                for (int x = 0; x < TKB[x].Count; x++)
                {
                    TKB_TUAN temp = TKB[z][x];
                    if (temp.Active)//check da xep chua, tra ve true neu chua xep
                    {

                        for (int i = 0; i < 28; i++)
                        {
                            if (mangTGDayClass[i] != 0)// check thoi gian co hop le ko
                            {

                                temp.ThoiGianBatDau = i;
                                //__Tim giao vien
                                for (int t = 0; t < lstTeacher.Count(); t++)
                                {
                                    if (TeachAccept(lstTeacher[t].GiangVienID, temp.LOPHOC.CTDT.MONHOC.ID) && mangTGDayGV[t, i] == 0)// check giao vien co the day ko
                                    {
                                        //Gan giang vien giang day
                                        temp.GiangVienID = lstTeacher[i].GiangVienID;

                                        for (int l = 0; l < temp.LOPHOC.SoTietTrongTuan; l++)
                                        {
                                            mangTGDayGV[t, i] = temp.LopHoc_ID;
                                        }
                                        break;
                                    }
                                }
                                //__Tim phong
                                for (int r = 0; r < lstPhong.Count(); r++)
                                {
                                    if (lstPhong[r].LoaiPhongID == temp.LOPHOC.LoaiPhong_ID && mangTGDayRoom[r, i] == 0)
                                    {
                                        temp.PhongID = lstPhong[r].ID;
                                        for (int l = 0; l < temp.LOPHOC.SoTietTrongTuan; l++)
                                        {
                                            mangTGDayRoom[r, i] = temp.LopHoc_ID;
                                        }
                                        break;
                                    }
                                }
                            }
                            if (temp.GiangVienID != null && temp.GiangVienID != 0 && temp.PhongID != null && temp.PhongID != 0)
                            {
                                mangTGDayClass[i] = temp.LopHoc_ID;
                                temp.Active = false;
                                TKB[z][x] = temp;
                            }
                            else
                            {
                                for (int l = 0; l < temp.LOPHOC.SoTietTrongTuan; l++)
                                {
                                    mangTGDayRoom[Convert.ToInt32(temp.PhongID), i] = 0;
                                    mangTGDayGV[Convert.ToInt32(temp.GiangVienID), i] = 0;
                                }
                            }
                        }

                    }
                }
            }
            return TKB;
        }
        private void SaveTKB(List<List<TKB_TUAN>> TKB)
        {
            for (int p = 0; p < db.TKB_TUAN.Count(); )
            {
                db.TKB_TUAN.DeleteObject(db.TKB_TUAN.First());
            }
            for (int i = 0; i < TKB.Count(); i++)
            {
                for (int j = 0; j < TKB[i].Count(); j++)
                {
                    db.TKB_TUAN.AddObject(TKB[i][j]);
                }
            }
        }
        public void CreateTimeTable()
        {
            List<List<TKB_TUAN>> TKB = Schedule();
            SaveTKB(TKB);
        }
       

        private List<TKB_TUAN> getAllTKBTheoKhoa()
        {
            string hocky= getHocKyHienTai();
            var khoa= getKhoaHocHienTai();
            var res = from p in db.TKB_TUAN where p.LOPHOC.KhoaHoc == khoa && p.LOPHOC.CTDT.HocKy_ID == int.Parse(hocky) select p;
            return res.ToList();

        }
        

        
        

        private bool TeachAccept(int GiangVienID,int MonhocID )
        {
            //throw new NotImplementedException();
            var res = from p in db.MONHOCGIANGDAYs where p.GiangVienID == GiangVienID && p.MonHocID == MonhocID select p;
            return (res != null && res.Count() > 0);
        }

        private List<CTDT> getAllCTDTTheoKhoaHocKy(int khoaID, int hocky)
        {
            var res = from p in db.CTDTs where p.Khoa_ID == khoaID && p.HocKy_ID == hocky select p;
            return res.ToList();
        }
        private List<KHOA> getAllKhoaTKB()
        {
            var res = db.KHOAs.ToList();
            //res.ForEach(e => db.Detach(e));
            return res;
        }
        private string getKhoaHocHienTai()
        {
            var res = (from p in db.CONFIGs where p.ThamSo == "KhoaHocHienTai" select p.GiaTri).First();
            return res;
        }
        private string getHocKyHienTai()
        {
            var res = (from p in db.CONFIGs where p.ThamSo == "HocKyHienTai" select p.GiaTri).First();
            return res;
        }
        private List<HOCKY> getAllHocKyDangHoc(string hockyhientai)
        {

            var res = from p in db.HOCKies where (p.HocKy1 % 2) == (int.Parse(hockyhientai) % 2) select p;
            return res.ToList();
        }

        private List<List<CTDT>> getAllCTDTTKB()
        {
            List<List<CTDT>> lstCTDT = new List<List<CTDT>>();
            var hockyhientai = getHocKyHienTai();// dau tien lay hoc ky hien tai la hoc ki 1 hay 2
            List<HOCKY> LstHocKy = getAllHocKyDangHoc(hockyhientai);// lay tat ca cac hoc ky dang hoc ung voi hoc ky hien tai, hk hien tai la 1 thi cac hoc ky dang hoc la 1,3,5...
            var lstKhoa = getAllKhoaTKB();
            for (int i = 0; i < lstKhoa.Count(); i++)
            {
                for (int j = 0; j < LstHocKy.Count(); i++)
                {
                    List<CTDT> lstCTDTTheoKhoa_HocKy = getAllCTDTTheoKhoaHocKy(lstKhoa[i].ID, LstHocKy[j].ID);//lay cac mon hoc thuoc chuong trinh dao tao cua cac khoa trong hoc ky nay
                    lstCTDT.Add(lstCTDTTheoKhoa_HocKy);
                }
            }
            return lstCTDT;
        }

        private List<LOPHOC> getAllLophocTheoCTDT(int CTDT_ID)
        {
            //throw new NotImplementedException();
            var khoahientai = getKhoaHocHienTai();
            var res = from p in db.LOPHOCs where p.KhoaHoc == khoahientai && p.CTDT_ID == CTDT_ID select p;
            return res.ToList();
        }
       
        private List<List<TKB_TUAN>> CreateTKB()// khoi tao tkb voi cac lop hoc và chưa co cac thong tin nhu giao vien, thoi gian hoc
        {
            //throw new NotImplementedException();
            List<List<TKB_TUAN>> tkb = new List<List<TKB_TUAN>>();
            //lay ds cac ctdt trong hk
            List<List<CTDT>> lstAllCTDT = getAllCTDTTKB();// lay danh sach cac mon roi chia nhom theo tung chuong trinh dao tao cua tung khoa va hoc ky dang hoc
            for (int i = 0; i < lstAllCTDT.Count(); i++)
            {
                for (int j = 0; j < lstAllCTDT[i].Count(); j++)
                {
                    List<LOPHOC> lstLopHoc = getAllLophocTheoCTDT(lstAllCTDT[i][j].ID); // lay tat ca cac lop trong chuong trinh dao tao
                    List<TKB_TUAN> lstTKBTheoCTDT = new List<TKB_TUAN>();
                    for (int k = 0; k < lstLopHoc.Count; k++)
                    {
                        TKB_TUAN tkb_tuan = new TKB_TUAN();
                        tkb_tuan.LopHoc_ID = lstLopHoc[k].ID;
                        lstTKBTheoCTDT.Add(tkb_tuan);
                    }
                    tkb.Add(lstTKBTheoCTDT);
                }
            }
            
                
                //--
            return tkb;

        }
        

        
        

       
        #endregion
    }
}
